package jwr.basic;

public class Ch04_Ex02 {

	public static void main(String[] args) {
		Rectangle r = new Rectangle();
		Rectangle s = new Rectangle(1, 1, 2, 3);
		
		r.show();
		s.show();
		System.out.println(s.square());
		r.setRect(-2,2,-1,-4);
		r.show();
		System.out.println(r.square());
		
		if(s.equals(r)){
			System.out.println("두 사각형은 같습니다.");
		}else{
			System.out.println("두 사각형은 다릅니다.");
		}
	}

}

class Rectangle{
	private int x1,y1,x2,y2,width,height;
	public Rectangle() {
	}
	public Rectangle(int x1,int y1, int x2, int y2) {
		this.x1 = x1;
		this.y1 = y1;
		this.x2 = x2;
		this.y2 = y2;
	}
	
	void setRect(int x1,int y1, int x2, int y2){
		this.x1 = x1;
		this.y1 = y1;
		this.x2 = x2;
		this.y2 = y2;
	}
	
	int square(){
		int s;
		this.width = x2-x1;
		this.height = y2-y1;
		s = width*height;
		return s;
	}
	void show(){
		System.out.println("넓이 : "+square()+" 가로 길이 : "+width+" 세로 길이 : "+height);
	}
	boolean equals(Rectangle r){
		boolean n;
		if(width == r.x2-r.x1 && height == r.y2-r.y1){
			n = true;
		}else{
			n = false;
		}
		return n;
	}
}